package tasks.Rules;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import core.FileOperator;
import dbops.ROW;
import dbops.SQLOperator;
import dbops.Table;
/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class Rule
{
	private String sqlRule;
	private String opportunityNumber;
	private String subgroup;
	
	//Patterns
	private final String oppDetail_pattern = "%OPP_NUMBER%";
	private final String subgroup_pattern = "%SUBGROUP%";
	
	public Rule(String ruleFileName, String opportunityNumber, String subgroup)
	{
		this.opportunityNumber = opportunityNumber;
		this.subgroup = subgroup;
		
		String rule = ruleLoader(ruleFileName);
		formatRule(rule);
	}
	
	private String ruleLoader(String ruleName)
	{
		String ruleTemplate = "";
		String fileParentDir = "tasks\\Rules\\";
		try {
			ruleTemplate = FileOperator.getContents(fileParentDir + ruleName);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ruleTemplate;
	}
	
	private void formatRule(String rule)
	{
		String tmpString = rule.replace(this.oppDetail_pattern, opportunityNumber);
		
		tmpString = tmpString.replace(this.subgroup_pattern, subgroup);
		
		sqlRule = tmpString;
	}
	
	public String getRule()
	{
		return sqlRule;
	}
	
}

